// pages/home/home.js
var {getGoodsList,swiperdata} = require('../../api/goods.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img:[

    ],
    img2:[
      "../../image/movie01.jpg",
      "../../image/movie02.jpg",
      "../../image/movie03.jpg",
      "../../image/movie04.jpg",
    ],

    goods:[
    ],
    category1:[
      {
        url:"../../image/大家电.png",
        text:"大家电"
      },
      {
        url:"../../image/手机相机.png",
        text:"手机相机"
      },
      {
        url:"../../image/电脑.png",
        text:"电脑办公"
      },
      {
        url:"../../image/汽车生活.png",
        text:"汽车生活"
      },
      {
        url:"../../image/家装建材.png",
        text:"家装建材"
      },
      {
        url:"../../image/居家生活.png",
        text:"居家生活"
      },
      {
        url:"../../image/个护健康.png",
        text:"个护健康"
      },
      {
        url:"../../image/全部.png",
        text:"全部"
      }
    ]
  },
  getGoodsListFun(){
    getGoodsList().then(data=>{
    console.log(data);
    if(data.meta.status == 200){
      let goodslist =data.message.goods;
      let lists = [];
      goodslist.forEach(item=>{
        let{goods_id,goods_name,goods_small_logo,goods_price} = item;
        let data ={
          id:goods_id,
          goodsImage:goods_small_logo,
          goodsName:goods_name,
          goodsPrice:goods_price == 0 ? "暂无报价":goods_price,   
          goodsPel:goods_price+600         
        }
        if(goods_small_logo){
          lists.push(data);
        }
      })
      this.setData({
        goods:lists
      })
    }
  })
  },
  swiperdataFun(){
    swiperdata().then(data=>{
      console.log(data);
      let imgs = data.message;
      this.setData({
        img:imgs
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getGoodsListFun()
    this.swiperdataFun();//轮播图
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})